package com.ruoyi.carShop.service.impl;


import com.ruoyi.carShop.mapper.MerchantVerificationMapper;
import com.ruoyi.carShop.service.LoginService;
import com.ruoyi.carShop.util.SmsUtil;
import com.ruoyi.system.api.domain.MerchantVerification;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Service
public class LoginServiceImpl implements LoginService {
    @Resource
    private RedisTemplate redisTemplate;
    @Resource
    private MerchantVerificationMapper loginMapper;
    @Override
    public Map createSms(String phoneNumber) {
        Map<String, String> map = new HashMap<>();
        String code = SmsUtil.createCode();
        System.out.println(code);
//        SmsUtil.send(phoneNumber, code);
        System.out.println(code);
        map.put(phoneNumber,code);
        // 存入redis
        redisTemplate.opsForValue().set(phoneNumber, code);
        return map;
    }

    @Override
    public MerchantVerification login(String mobile) {
      return loginMapper.selectByMobile(mobile);
    }
}
